home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
DB_CLIPP
/
0411.ZIP
/
RCVBLK.C
< prev
next >
Wrap
Text File
|
1985-04-01
|
4KB
|
112 lines
/*
* receive blocks of data
*/
#define BLKLENTH 128
#define SEQLENTH 2
#define CHKSMLEN 2
#define NOT_END endfound==0
#define LAST_BLK shortblk==1
#define ENDOFBLK '+'
rcvblk()
{
/*
* Declarations
*/
short rcvcntr, /* */
inpcntr, /* No of bytes in this block */
lastblck, /* Last block's sequence no */
blockno, /* Current block no */
shortblk, /* Short block flag */
sequno[SEQLENTH+1], /* Current sequence no array */
block[BLKLENTH+1], /* Data array */
checksum[CHKSMLEN+1], /* Checksum array */
compchk, /* Computed checksum var */
com1, /* Input file descriptor var */
endfound, /* End of transmission flag */
cntr; /* General purpose counter */
/*
* Initialise
*/
rcvcntr = 0; /* No of blocks received */
endfound = 0; /* End not yet found */
lastblck = 0; /* Next block no should be 1 */
sequno[SEQLENTH+1] = '\0'; /* Initialise to valid string */
block[BLKLENTH+1] = '\0'; /* Initialise to valid string */
checksum[CHKSMLEN+1] = '\0'; /* Initialise to valid string */
com1 = fopen("a:com1.dat","r"); /* Open COM1 for input */
/*
* Begin processing
*/
while (NOT_END)
{
/*
* Read the sequence number
*/
for (cntr = 1, cntr <= SEQLENTH, ++cntr)
{
seqno[cntr] = fgetc(com1);
if (seqno[cntr] == EOF) /* Check for error or EOF */
endfound = 1;
}
/*
* Check for ET (End of Transmission)
*/
if (NOT_END)
{
if (seqno[] == "ET")
{
endfound = 1;
}
}
/*
* Convert the sequence chars to a valid no
*/
if (NOT_END)
{
if (isdigit(seqno[1]) && isdigit(seqno[2]))
{
blockno = atoi(seqno[]); /* This block's no */
if (blockno != lastblck+1)
endfound = 1;
else
++lastblck;
}
else
endfound = 1;
}
/*
* Receive 128 chars and compute checksum
*/
if (NOT_END)
{
++rvccntr;
compchk = 0;
for (inpcntr=1, inpcntr <= BLKLENTH, ++inpcntr)
{
block[inpcntr] = fgetc(com1);
if (block[inpcntr] = ENDOFBLK)
{
shortblk = 1;
inpcntr = BLKLENTH + 1;
}
else
compchk = ((compchk + block[inpcntr])/100);
}
}
/*
* Read checksum
*/
if (NOT_END)
{
checksum = 0;
for (cntr = 1, cntr <= CHKSMLEN, ++cntr)
checksum[cntr] = fgetc(com1);
/*
* Compare checksum
*/
if (compchk != atoi(checksum[])
endfound = 1;
}
}
}